<template>
	<view class="content">
			<button type="primary" plain open-type="getUserInfo" @click="handleinfo" > 登录 </button>
			<button type="primary"  @click="handleinfo2" > 测试 </button>
	</view>
</template>

<script>
	export default { 
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
				
			handleinfo(e){
				// console.log(e)
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
				    // console.log(loginRes.authResult);
				    // 获取用户信息
				    uni.getUserInfo({
				      provider: 'weixin',
				      success: function (infoRes) {
						// console.log(infoRes)
				        // console.log('用户昵称为：' + infoRes.userInfo.nickName);
						const {userInfo} = infoRes;
						uni.setStorageSync("userInfo",userInfo);
				      }
				    });
				  }
				});
				
				uni.navigateBack({
					delta: 1
				});
				
			
			},
			handleinfo2(){
				const userInfo = {
					avatarUrl:"https://img0.baidu.com/it/u=2028084904,3939052004&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
					nickName:"nickName",
					appid:'123456'
				}
				const res = this.$myRequest({
					url:'/login',
					data: userInfo,
					method:'post'
				})
				uni.setStorageSync("userInfo",userInfo);
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style>
	button{
	  margin-top: 40rpx;
	  width: 70%;
	}
</style>
